<template>
	<view class="padd">
		<view class="welcomeTxt">
			<view class="welTxt">欢迎登录</view>
			<view>清北AI自习室</view>
		</view>
		<view class="loginItem">
			<input type="text" class="input" name="phoneNum" v-model="phoneNum" placeholder="请输入账号" maxlength="28" placeholder-class="holderInp"/>
		</view>
		<view class="loginItem">
			<input type="password" class="input" name="phoneNum" v-model="password" placeholder="请输入密码" maxlength="28" placeholder-class="holderInp"/>
		</view>
		<button class="comBtn" @tap="goLogin" :loading="isDisabled" :disabled="isDisabled">{{loginTxt}}</button>
	</view>
</template>

<script>
	import { doZxLogin } from '@/api/zhuxue.js'
	export default {
		data() {
			return {
				phoneNum:'',
				password:'',
				isAgreeFlag:false,
				loadOpt : '',
				isDisabled:false,
				loginTxt:'登录',
				canRefreshFlag:0,//loadOpt == '' 时 0上个页面不刷新接口 1上个页面刷新接口
				popupShow:false,
				loginType:''
			}
		},
		onLoad(options){
			//userFix->关注 去预约 //userFixNoRef只返回不刷新
			this.canRefreshFlag = options.canRefreshFlag;
			this.loadOpt = options.loadOpt;
		},
		methods: {
			goLogin(){ 
				if(this.phoneNum == ''){
					this.util.showToast('请输入账号');
				}else if(this.password == ''){
					this.util.showToast('请输入密码');
				}else{
					this.commonAccLogin();
				}
			},
			commonAccLogin(){
				uni.showLoading({ title: '登录中...', mask: true });
				var field = {account:this.phoneNum,password:this.password};
				this.isDisabled = true;
				doZxLogin(field).then(res=>{
					var tmpRes = res.data.datas;
					uni.setStorageSync("token", tmpRes.account);
					uni.setStorageSync("groupUserRole",tmpRes.roleName);
					uni.setStorageSync('userId',tmpRes.userId);
					if(tmpRes.roleName != '学生'){
						uni.setStorageSync('userPortrait',this.defHead);
						uni.setStorageSync('realName',tmpRes.realName);
					}else{
						uni.setStorageSync('gradeNo',tmpRes.gradeNo);
						uni.setStorageSync('gradeName',tmpRes.gradeName);
					}
					uni.showToast({ title: '登录成功' });
					setTimeout(()=>{
						// 返回上一步
						if(Number( this.canRefreshFlag ) == 1){
							let pages = getCurrentPages();
							let prevPage = pages[pages.length - 2];
							prevPage.$vm.isRefreshFlag = true;
						}
						uni.navigateBack({ delta: 1 });
						this.isDisabled = false;
					},1500);
				}).catch(err=>{
					this.isDisabled = false;
					console.log(err)
				});
			},
		}
	}
</script>
<style lang="scss">
	page{background:#fff;}
	.holderInp{
		font-weight: normal;
		color: $pss-text-colora;
		@include respTo(phone){
			font-size: $font-size30;
		}
		@include respTo(pad){
			font-size: $padSize16;
		}
	}
</style>
<style lang="scss" scoped>
	.welcomeTxt{
		margin:260rpx 0 100rpx 0;
		color: $pss-text-colora;
		@include respTo(phone){
			font-size: $font-size26;
		}
		@include respTo(pad){
			font-size: $padSize14;
		}
		.welTxt{
			font-weight: 600;
			color: $pss-text-color3;
			margin-bottom: 10rpx;
			@include respTo(phone){
				font-size: 46rpx;
			}
			@include respTo(pad){
				font-size: 28rpx;
			}
		}
	}
	.loginItem{
		border-radius: 50rpx;
		background: #F7F9FC;
		margin-bottom: 50rpx;
		.input{
			color: $pss-text-color3;
			font-weight: 600;
			@include respTo(phone){
				padding: 0 50rpx;
				height: 100rpx;
				font-size: $font-size32;
			}
			@include respTo(pad){
				padding: 0 30rpx;
				height: 70rpx;
				font-size: $padSize18;
			}
		}
	}
	.comBtn{
		margin-top: 120rpx;
		border-radius: 50rpx;
		@include respTo(phone){
			font-size: $font-size30;
		}
		@include respTo(pad){
			height: 70rpx;
			line-height: 70rpx;
			font-size: $padSize20;
		}
	}
</style>
